package com.robot.orders.mq;

import com.alibaba.fastjson.JSON;
import com.robot.orders.dao.OrdersDao;
import com.robot.orders.pojo.Orders;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
@RabbitListener(queues = "dingdan")
public class OrdersListener {
    @Autowired
    private OrdersDao ordersDao;

    @RabbitHandler
    public void exec(String str){

        if(str.startsWith("orders")){
            str=str.replace("orders","");
            Orders orders= JSON.parseObject(str,Orders.class);
            orders.setPayment("10");
            ordersDao.save(orders);

            //agent_id
            orders.setAgentId("");

            orders.setPayment("10");
            ordersDao.save(orders);
            System.out.println(orders);
        }else if(str.startsWith("buyVip")){
            str=str.replace("buyVip","");

            Orders orders=JSON.parseObject(str,Orders.class);
            orders.setPayment("10");
            orders.setRate(1.0);
            orders.setPayAmount(orders.getPrice());
            orders.setTotalRevenue(orders.getPrice());
            orders.setRevenue(orders.getPrice());
            BigDecimal zero=new BigDecimal("0");
            orders.setRoyalty(zero);
            orders.setAgentRevenue(zero);
            orders.setDiscountAmount(zero);
            orders.setPayment("11");
            ordersDao.save(orders);

        }
    }
}